﻿using System;

namespace TShooter.TfsSearch.EngineModel
{
    public sealed class DocumentReference : IEquatable<DocumentReference>
    {
        #region Constructors and Member variables

        private readonly int _ID = -1;
        private readonly int _Revision;
        private readonly string _Path;

        public DocumentReference(int id, int revision)
        {
            _ID = id;
            _Revision = revision;
        }

        public DocumentReference(string path, int revision)
        {
            _Path = path;
            _Revision = revision;
        }

        #endregion

        #region Properties

        public int ID
        {
            get { return _ID; }
        }

        public int Revision
        {
            get { return _Revision; }
        }

        public string Path
        {
            get { return _Path; }
        }

        #endregion

        #region IEquatable members

        public bool Equals(DocumentReference documentReference)
        {
            if (documentReference == null) return false;
            if (ID != documentReference.ID) return false;
            if (Revision != documentReference.Revision) return false;
            if (!Equals(Path, documentReference.Path)) return false;
            return true;
        }

        #endregion

        #region Overrides

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj)) return true;
            return Equals(obj as DocumentReference);
        }

        public override int GetHashCode()
        {
            int result = ID;
            result = 29*result + Revision;
            result = 29*result + (Path != null ? Path.GetHashCode() : 0);
            return result;
        }

        #endregion
    }
}
